package com.haixiaoke.flat.contract.controller;

import com.haixiaoke.auth.AuthCheck;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.contract.domain.LesseeContract;
import com.haixiaoke.saas.contract.domain.ProprietorContract;
import com.haixiaoke.saas.contract.service.IProprietorContractService;
import com.haixiaoke.saas.system.BaseController;
import com.haixiaoke.token.FrontTokenComponent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 业主合同管理Controller
 *
 * @author xiaolong
 * @date 2024-06-17
 */
@RestController
@RequestMapping("/front/flat/contract/proprietorContract")
public class FlatProprietorContractController extends BaseController {
    @Autowired
    private IProprietorContractService proprietorContractService;
    @Autowired
    private FrontTokenComponent frontTokenComponent;

    /**
     * 查询业主合同管理列表
     */
    @AuthCheck
    @GetMapping("/list")
    public TableDataInfo list(ProprietorContract proprietorContract) {
        startPage();
        proprietorContract.setProprietorUserId(frontTokenComponent.getUserIdNotNull());
        List<ProprietorContract> list = proprietorContractService.selectProprietorContractByProprietorUserId(proprietorContract);
        return getDataTable(list);
    }


    /**
     * 删除业主合同管理
     */
    @AuthCheck
    @DeleteMapping("/{proprietorContractId}")
    public AjaxResult remove(@PathVariable String proprietorContractId) {
        return toAjax(proprietorContractService.updateProprietorContractByProprietorContractId(proprietorContractId));
    }

    /**
     * 获取业主合同管理详细信息
     */
    @GetMapping(value = "/{proprietorContractId}")
    public AjaxResult getInfo(@PathVariable("proprietorContractId") String proprietorContractId) {
        return success(proprietorContractService.selectProprietorContractByProprietorContractId(proprietorContractId));
    }

    /**
     * 获取预览电子合同内容链接
     */
    @AuthCheck
    @PostMapping(value = "/previewUrl")
    public AjaxResult electronicVisaPreviewUrl(@RequestBody ProprietorContract proprietorContract) {
        return AjaxResult.success("操作成功", proprietorContractService.selectProprietorContractElectronicVisaPreviewUrl(proprietorContract));
    }

    /**
     * 签订合同
     */
    @AuthCheck
    @PutMapping("/signing")
    public AjaxResult lesseesSigning(@RequestBody ProprietorContract contract) {
        return proprietorContractService.signingLesseeContract(contract, frontTokenComponent.getUserIdNotNull());
    }
}
